Forums

PHP

This topic is locked

sub headings in dynamic dropdown menus

Posted 08 Mar 2005 12:30:47
1
has voted
08 Mar 2005 12:30:47 Geofrey Biggins posted:
HI, my website has different sections and within each section there is a dynamic dropdown menu which lists the pages within that section from a mysql database. I would like to be able to put subheaders in the dropdown but if i do then people can click on them and the page will change to one that doesn't exist as it would just be a title and no content as I have a submit on change command on the menu so that when people select one it automatically goes to the page. can anyone suggest how i can put subheaders in that won't link to a page. Iam using php and mysql. Iam thinking it may involve echoing the subheading but ive no idea how to do it. this is the code i am using for the form

<pre id=code><font face=courier size=2 id=code> &lt;form name="form1" method="get" action=""&gt;
&lt;p&gt;&lt;font face="Trebuchet MS, Arial, sans-serif"&gt;
&lt;select name="title" id="title" onChange="document.all.form1.submit()";&gt;
&lt;option value=""&gt;other topics in marine world&lt;/option&gt;
&lt;?php
do {
?&gt;
&lt;option value="&lt;?php echo $row_Recordset2['title']?&gt;"&gt;&lt;?php echo $row_Recordset2['title']?&gt;&lt;/option&gt;
&lt;?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
$rows = mysql_num_rows($Recordset2);
if($rows &gt; 0) {
mysql_data_seek($Recordset2, 0);
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
}
?&gt;
&lt;/select&gt;
&lt;/font&gt; &lt;noscript&gt;
&lt;input type="submit" name="Submit" value="go" &gt;
&lt;/noscript&gt;&lt;/p&gt;
&lt;/form&gt;&lt;/td&gt;
</font id=code></pre id=code>

Replies

Replied 09 Mar 2005 15:28:36
09 Mar 2005 15:28:36 Matt Bailey replied:
Geofrey

If i've misunderstood what you want to do then let me know, but you could store your subheadings in the database as well and then just 'echo' these in the dropdown menu alongside the titles.

For example, this is how it could look to someone in the dropdown menu:

Subheading 1 - Title 1
Subheading 2 - Title 2
Subheading 3 - Title 3
etc...

The relevant code would therefore need to be something like this:

<pre id=code><font face=courier size=2 id=code>&lt;option value="&lt;?php echo $row_Recordset2['title']?&gt;"&gt;&lt;?php echo $row_Recordset2['subheading']?&gt; - &lt;?php echo $row_Recordset2['title']?&gt;&lt;/option&gt;</font id=code></pre id=code>

So the value of each item in the menu is 'title', but it displays 'subheading' and 'title'. Presumably you are then sending the user to a detail page that filters the recordset by 'title'.

Is that any help?

___________________________________
* Sorry... how do you do that again?... *
Replied 09 Mar 2005 19:05:38
09 Mar 2005 19:05:38 Chris Charlton replied:
Look up the tag <b>&lt;optgroup&gt;</b>, it may be what you're looking for... and an underused tag.

~ ~ ~ ~ ~ ~ ~
Chris Charlton <i>- DMXzone Manager</i>
<font size=1>[ Studio MX/MX2004 | PHP/ASP | SQL | XHTML/CSS | XML | Actionscript | Web Accessibility | MX Extensibility ]</font id=size1>

Reply to this topic